define([
	'layer',
	'xss',
	'../../Shop/module/STH_main.js',
], function(layer, xss, main) {

	return {
		vedioAddM: function(con) { 
			var _this = this,
				key = con.key,
				order = con.order,
				prop = con.prop, 
				vediosrc = prop.vediosrc,

				newPanel = main.getPanel("vedio"),
				newEdit = main.getEdit("vedio");

			//属性操作
			$(newPanel).attr("order", order);
			$(newPanel).attr("key", key);
			$(newEdit).attr("key", key);
			$(newEdit).css("display", "none");

			if(vediosrc != "") {
				$(newPanel).find(".STH_vedio_box video").show();
				$(newPanel).find(".STH_vedio_box div").hide();
				$(newPanel).find(".STH_vedio_box video").attr("src", vediosrc);

			}

			//延时顺序重定位
			var edLength = $(".hb_box .panel-comp").length;
			if($(".hb_box .panel-comp").length < 1 || order > parseInt($(".hb_box .panel-comp").eq(edLength - 1).attr("order"))) {
				$(".hb_box").append(newPanel);
			} else if(order < parseInt($(".hb_box .panel-comp").eq(0).attr("order"))) {
				$(".hb_box").prepend(newPanel);
			} else {
				for(var r = 0; r < edLength; r++) {
					if(order > parseInt($(".hb_box .panel-comp").eq(r).attr("order")) && order < parseInt($(".hb_box .panel-comp").eq(r + 1).attr("order"))) {
						$(".hb_box .panel-comp").eq(r).after(newPanel);
						break;
					}
				}
			}
			$(".edit-panel").append(newEdit);
			_this.vedioActive(newPanel, newEdit, key);
		},

		vedioActive: function(thisPanel, thisEdit, key) {
			var _this = this;
			if(typeof(g_data[key].prop.vediosrc) == "undefined") {
				g_data[key].prop = {
					"vediosrc": ""
				}
			}

			$(thisEdit).find(".video_btn").unbind("click").click(function() {
				main.commonDialog('vcommon/common/VideoList.html', "添加视频", 880, 680, function(res) {

					g_data[key].prop.vediosrc = res.Fpath;
					$(thisPanel).find(".STH_vedio_box div").hide();
					$(thisPanel).find(".STH_vedio_box video").attr("src", res.Fpath);
					$(thisPanel).find(".STH_vedio_box").find("video").show();  

				});
			});
 

			//调用主模板JS
			main.saveClick();
			main.moduleActive();
			main.dragEdit();
		}
	}
});